<#import "/layout/mainLayout.html" as mainLayout />

<#macro mainheading>

</#macro>
<#assign mainheading = mainheading in mainLayout />

<#macro maincontent>
    <section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="row">
                        <div class="col-sm-2">
                            <select class="form-control" id="input_state">
                                <option value="-1">--用户状态--</option>
                                <option value="0">正常</option>
                                <option value="1">锁定</option>
                            </select>
                        </div>

                        <div class="col-sm-2">
                            <input type="text" class="form-control" id="input_nick" placeholder="昵称...">
                        </div>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" id="input_phone" placeholder="电话...">
                        </div>

                        <div class="col-sm-1 pull-right">
                            <button class="btn btn-block btn-default " id ="btn_search" onclick="searchStudents()">查询
                            </button>
                        </div>
                    </div><!-- /.box-header -->
                </div>
                <div class="box-header">
                    <div class="row">
                        <div class="col-sm-9">
                        </div>
                        <div class="col-sm-3">
                            <a class="btn btn-block btn-success" href="/page/admin/useradd">+
                                添加用户</a>
                        </div>
                    </div>
                </div>
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tbody>
                        <thead>
                        <tr>
                            <th>头像</th>
                            <th>姓名</th>
                            <th>电话</th>
                            <th>角色</th>
                            <th>状态</th>
                            <th>注册时间</th>
                            <th style="text-align: center">操作</th>
                        </tr>
                        </thead>
                        <tbody id="bodycontent">


                        </tbody>
                    </table>
                </div><!-- /.box-body -->
                <div id="pagecontent" class="pagination"></div>
            </div><!-- /.box -->
        </div>
    </div>
    </section>
</#macro>
<#assign maincontent = maincontent in mainLayout />

<#macro mainfooter>
    <!--layoutmain footer...-->
    <!--<br />-->
    <script src="/js/jquery/jquery.form.js"></script>

    <script type="text/javascript">

        var user_data = {
        };

        function searchStudents() {


            user_data = {
                state:$('#input_state').val(),
                username:$('#input_nick').val(),
                phone:$('#input_phone').val(),
                pno: 1,
                pagesize: 10,
                allcount:-1
            };
            LoadUserList();
        }
        //加载列表
        searchStudents();
        function LoadUserList() {
            $('#pagecontent').html('');
            $.ajax({
                    url: '/api/adminuser/userlist',
                    data: user_data,
                    dataType: 'json',
                    success: function (data) {
                        if (mortise_layout.ValidataResult(data)) {
                            if (data.result) {
                                user_data.allcount = data.result.count;
                                var html = '';
                                $.each(data.result.list, function (index, item) {
                                    html += getHtml(item);
                                })
                                $('#bodycontent').html(html);
                                ShowPage('pagecontent', user_data, function (pno) {
                                    user_data.pno = pno;
                                    LoadUserList();
                                });
                            }
                            else {
                                alert('返回数据错误！');
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
        function  getHtml(dataObject) {
            var regAppHtml='';
            if (dataObject.fState==0){
                regAppHtml= '<span class="label label-success">正常</span>'
            }
            else if (dataObject.fState=='1'){
                regAppHtml= '<span class="label label-danger">锁定</span>'
            }
            return ' <tr>'+
                '<td><img style="width: 40px;height: 40px;" src="'+dataObject.fPhoto+'"></td>'+
                '<td>'+dataObject.fUsername+'</td>'+
                '<td>'+dataObject.fPhone+'</td>'+
                '<td>'+dataObject.fRole+'</td>'+
                '<td>'+regAppHtml+'</td>'+
                '<td>'+dataObject.fIntime+'</td>'+
                '<td>' +
                '<a style="cursor: pointer" href="/page/user/userinfo?userid='+dataObject.fId+'">详情</a>&nbsp;&nbsp;' +
                '<a style="cursor: pointer" href="#" onclick="UpdateSateUser(\''+dataObject.fId+'\',1)">禁用</a>&nbsp;&nbsp;' +
                '<a style="cursor: pointer" href="#" onclick="UpdateSateUser(\''+dataObject.fId+'\',0)">恢复</a></td>'+
                '</tr>';
        }
        function UpdateSateUser(uid,state) {
            $.ajax({
                    url: '/api/user/updateuserstate',
                    data: {userid: uid,state:state},
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            if (data.code=='OperateOk'){
                                dialog({
                                    title:'提示',
                                    content: '操作成功！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                                LoadUserList();
                            }
                            else{
                                dialog({
                                    title:'提示',
                                    content: '操作失败！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
    </script>
</#macro>
<#assign mainfooter = mainfooter in mainLayout />
<@mainLayout.page title="用户管理"/>